package cn.kgc.login.controller;

import cn.kgc.common.entity.Author;
import cn.kgc.login.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by teacher ZHANG on 2023/2/7
 */
@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/users")
    public Boolean saveAuthor(String token, @RequestBody Author author) {
        userService.saveAuthor(token, author);

        return true;
    }

    @GetMapping("/users/{token}")
    public Author findAuthor(@PathVariable String token) {
        return userService.findAuthor(token);
    }

    @PostMapping("/codes")
    public Boolean savePhone(String phone, String code) {
        userService.savePhone(phone, code);
        return true;
    }

    @GetMapping("/codes")
    public String getPhone(String phone) {
        return userService.getPhone(phone);
    }
}
